﻿@page "/water"
@inject WebviewAppTest.AppState AppState
@inject IJSRuntime JSRuntime  
@inject NavigationManager NavigationManager

<h1>Water</h1>

<p>Demo from https://github.com/evanw/webgl-water</p>

<style type="text/css">
    body { font: 13px/140% Arial, sans-serif; overflow: hidden; background: black; }
    a { color: inherit; cursor: pointer; }
    
    ul { padding: 0 0 0 20px; }
    h1 { font: bold italic 30px/30px Georgia; text-align: center; }
    h2 { font: bold italic 17px/17px Georgia; padding-top: 10px; }
    small { display: block; font-size: 11px; line-height: 15px; }
    canvas { position: absolute; top: 0; left: 250px; }
    #help { position: absolute; top: 0; right: 0; bottom: 0; width: 280px; padding-right: 0px; overflow: auto; color: white; z-index: 1000; margin-top: 80px;}
    #loading { position: absolute; left: 200px; top: 50%; right: 300px; text-align: center; margin-top: -8px; }

</style>

    <div id="loading">Loading...</div>
    <div id="help">
        <h1>WebGL Water</h1>
        <p>Made by <a href="http://madebyevan.com/">Evan Wallace</a></p>
        <p>This demo requires a decent graphics card and up-to-date drivers. If you can't run the demo, you can still <a href="http://youtube.com/watch?v=R0O_9bp3EKQ">see it on YouTube</a>.</p>
        <h2>Interactions:</h2>
        <ul>
            <li>Draw on the water to make ripples</li>
            <li>Drag the background to rotate the camera</li>
            <li>Press SPACEBAR to pause and unpause</li>
            <li>Drag the sphere to move it around</li>
            <li>Press the L key to set the light direction</li>
            <li>Press the G key to toggle gravity</li>
        </ul>
        <h2>Features:</h2>
        <ul>
            <li>Raytraced reflections and refractions</li>
            <li>Analytic ambient occlusion</li>
            <li>Heightfield water simulation *</li>
            <li>Soft shadows</li>
            <li>Caustics (see <a href="https://medium.com/evanwallace/rendering-realtime-caustics-in-webgl-2a99a29a0b2c">this</a> for details) **</li>
        </ul>
        <p><small>* requires the OES_texture_float extension<br>** requires the OES_standard_derivatives extension</small></p>
        <p><small>Tile texture from <a href="http://www.flickr.com/photos/zooboing/3682834083/">zooboing</a> on Flickr</small></p>
    </div>


@code {

    protected override void OnInitialized()
    {
      // Subscribe to the event
      NavigationManager.LocationChanged += LocationChanged;
      base.OnInitialized();
    }

    void LocationChanged(object sender, LocationChangedEventArgs e)
    {
      // force a page reload when navigating away from the Water demo because it crashes on reload otherwise
      NavigationManager.NavigateTo(e.Location, forceLoad: true);
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await JSRuntime.InvokeVoidAsync("window.startWaterDemo", new object[] { "hi" });
    }

} 